<?php
namespace app\my\service;
use app\my\model\IndexModel;
use app\my\validata\MyValidata as mv;
use app\base\service\BaseService;
use think\facade\Log;
//我的类
class IndexService extends BaseService 
{ 
	protected $my='';
	protected $mv='';
	public function __construct()
	 {
	 	parent::__construct();
	 	$this->my = new IndexModel;
	 	$this->mv = new mv;
	 }
//我的个人信息
	 public function indexs($data){
	 	if(isset($data['Openid'])&&empty($data['Openid'])){
	 		$where['Userid'] = (isset($data['Userid'])&&!empty($data['Userid']))?$data['Userid']:$this->user['Userid'];
	 	}else{
	 		$where['Openid'] = (!empty($data['Openid']))?$data['Openid']:$this->user['Openid'];
	 	}
	 	
	 	$res = $this->my->findByAttributes('userinfo',$where,"*");
	 	if(empty($res)) return $this->return_code(202,'用户找不到');
	 	$res['currToken'] = $res['Token'];
	 	$res['Token'] = $res['defaultToken'];
	 	unset($res['Userpwd'],$res['Isuse'], $res['defaultToken'],$res['power']);
	 	return $this->return_code(200,'成功',$res);
	 }

	 //修改我的个人信息
	 public function edit_user($data){
	 	if (!$this->mv->scene('edit_user')->check($data)) {
            return $this->return_code(300,$this->mv->getError());
        }
        $my['Usernickname'] =$data['Usernickname'];
		$my['sex'] =$data['sex'];
		$my['birthday'] =$data['birthday'];
		$my['address'] =$data['address'];
		if(isset($data['UserImg'])&&!empty($data['UserImg'])&&!is_null($data['UserImg'])){
			$image=$this->upload_one_img($data['UserImg']);
			if(!$image['code']==200)  return $this->return_code($image['code'],$image['msg']);
	        	$my['UserImg']=$image['imagepath'];
		}
		
		$where['Userid'] = $this->user['Userid'];
        $id = $this->my->updateByWhere('userinfo',$where,$my);
        if($id){
        	 return $this->return_code(200,'修改成功');
        }
        return  $this->return_code();
	 } 



}